Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@yarnpkg/libzip

Package Overview
Dependencies
Maintainers
6
Versions
93
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@yarnpkg/libzip

  • 2.3.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.1M
decreased by-61.55%
Maintainers
6
Weekly downloads
 
Created

What is @yarnpkg/libzip?

@yarnpkg/libzip is a library that provides functionalities for working with ZIP archives. It is part of the Yarn package manager's ecosystem and allows for creating, reading, and manipulating ZIP files programmatically.

What are @yarnpkg/libzip's main functionalities?

Creating a ZIP Archive

This code demonstrates how to create a ZIP archive and add a file to it using @yarnpkg/libzip. The `makeInterface` function initializes the libzip interface, and `ZipFS` is used to create and manipulate the ZIP file.

const { makeInterface } = require('@yarnpkg/libzip');
const { ZipFS } = require('@yarnpkg/fslib');

(async () => {
  const libzip = await makeInterface();
  const zipFs = new ZipFS(null, { libzip });

  zipFs.writeFileSync('/file.txt', 'Hello, world!');
  zipFs.saveAndClose();
})();

Reading a ZIP Archive

This code demonstrates how to read a ZIP archive and extract a file's content using @yarnpkg/libzip. The ZIP file is read from the filesystem, and `ZipFS` is used to access and read the file within the archive.

const { makeInterface } = require('@yarnpkg/libzip');
const { ZipFS } = require('@yarnpkg/fslib');
const fs = require('fs');

(async () => {
  const libzip = await makeInterface();
  const zipData = fs.readFileSync('archive.zip');
  const zipFs = new ZipFS(zipData, { libzip });

  const content = zipFs.readFileSync('/file.txt', 'utf8');
  console.log(content); // Outputs: Hello, world!
})();

Listing Files in a ZIP Archive

This code demonstrates how to list all files in a ZIP archive using @yarnpkg/libzip. The ZIP file is read from the filesystem, and `ZipFS` is used to list the files within the archive.

const { makeInterface } = require('@yarnpkg/libzip');
const { ZipFS } = require('@yarnpkg/fslib');
const fs = require('fs');

(async () => {
  const libzip = await makeInterface();
  const zipData = fs.readFileSync('archive.zip');
  const zipFs = new ZipFS(zipData, { libzip });

  const files = zipFs.readdirSync('/');
  console.log(files); // Outputs: ['file.txt']
})();

Other packages similar to @yarnpkg/libzip

FAQs

Package last updated on 16 Mar 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc